
package fcy;

import android.content.Context;
import android.widget.TextView;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.xxmassdeveloper.mpchartexample.R;
import com.xxmassdeveloper.mpchartexample.model.MarkerInfo;

/**
 * Custom implementation of the MarkerView.
 * 
 * @author Philipp Jahoda
 */
public class TopMarkerView extends MarkerView {

    private TextView tv_rank,tv_area,tv_price;

    public TopMarkerView(Context context, int layoutResource) {
        super(context, layoutResource);

        tv_rank = (TextView) findViewById(R.id.tv_rank);
        tv_area = (TextView) findViewById(R.id.tv_area);
        tv_price = (TextView) findViewById(R.id.tv_price);
    }

    // callbacks everytime the MarkerView is redrawn, can be used to update the
    // content (user-interface)
    @Override
    public void refreshContent(Entry e, Highlight highlight) {

        //if (e instanceof CandleEntry) {
        //
        //    CandleEntry ce = (CandleEntry) e;
        //
        //    tvContent.setText("" + Utils.formatNumber(ce.getHigh(), 0, true));
        //} else {
        //
        //    tvContent.setText("" + Utils.formatNumber(e.getVal(), 0, true));
        //}
        if (e != null) {
            MarkerInfo markerInfo = (MarkerInfo) e.getData();
            tv_rank.setText(markerInfo.top);
            tv_area.setText(markerInfo.district_name);
            tv_price.setText(markerInfo.onsale_price);
        } else {
            //tv_rank.setText("");
            //tv_area.setText("");
            //tv_price.setText("");
        }
    }

    @Override
    public int getXOffset(float xpos) {
        // this will center the marker-view horizontally
        return -(getWidth() / 2);
    }

    @Override
    public int getYOffset(float ypos) {
        // this will cause the marker-view to be above the selected value
        return -getHeight();
    }
}
